<!-- S search -->
<app-search-bar
  [submitLoading]="tableParams.loading"
  [searchOptions]="searchOptions"
  labelFlex="110px"
  (onSearch)="queryResetData($event)"
  (onReset)="queryResetData($event)"
>
</app-search-bar>
<!-- E search -->

<nz-card class="m-t-4">
  <div class="opera-wrap">
    <button
      nz-button
      nzType="primary"
      [nzLoading]="exportLoading"
      (click)="exportTable()"
    >导出</button>

    <button
      nz-button
      nzType="primary"
      class="m-l-10"
      (click)="showBatchModal()"
    >批量作废</button>
  </div>

  <div class="pagination-wrap-position p-t-10">
    <nz-table
      #basicTable
      nzSize="small"
      nzShowSizeChanger
      nzShowQuickJumper
      nzOuterBordered
      [nzScroll]="{ x: '1100px' }"
      [nzFrontPagination]="false"
      [nzLoadingDelay]="100"
      [nzLoading]="tableParams.loading"
      [nzData]="tableParams.tableData"
      [nzPageSizeOptions]="[5, 10, 20, 50, 100]"
      [nzTotal]="tableParams.total"
      [nzPageIndex]="tableParams.page"
      [nzPageSize]="tableParams.pageSize"
      [nzShowTotal]="totalTemplate"
      (nzPageIndexChange)="onPageIndexChange($event)"
      (nzPageSizeChange)="onPageSizeChange($event)"
    >
      <thead>
        <tr>
          <th nzAlign="center" nzWidth="190px">兑换码</th>
          <th nzAlign="center" nzWidth="180px">批次号</th>
          <th nzAlign="center" nzWidth="120px">状态</th>
          <th nzAlign="center" nzWidth="190px">关联用户优惠券ID</th>
          <th nzAlign="center" nzWidth="120px">券包ID</th>
          <th nzAlign="center" nzWidth="180px">券包名称</th>
          <th nzAlign="center" nzWidth="170px">生成时间</th>
          <th nzAlign="center" nzWidth="170px">兑换时间</th>
          <th nzAlign="center" nzWidth="170px">过期时间</th>
          <th nzAlign="center" nzWidth="150px" nzRight>操作</th>
        </tr>
      </thead>

      <tbody>
        <tr *ngFor="let data of basicTable.data; let index = index;">
          <!-- 兑换码 -->
          <td nzAlign="center">{{ data.no || '-' }}</td>
          <!-- 批次号 -->
          <td nzAlign="center">{{ data.lotNo || '-' }}</td>
          <!-- 状态 -->
          <td nzAlign="center">
            <span [ngStyle]="{'color': data.status | changeCodeStatus: 'color'}">
              {{ data.status | changeCodeStatus: 'label' }}
            </span>
          </td>
          <!-- 关联用户优惠券ID -->
          <td nzAlign="center">{{ data.userRecordId || '-' }}</td>
          <!-- 券包ID -->
          <td nzAlign="center">{{ data.packageId || '-' }}</td>
          <!-- 券包名称 -->
          <td nzAlign="center">{{ data.packageName || '-' }}</td>
          <!-- 生成时间 -->
          <td nzAlign="center">{{ data.createTime || '-' }}</td>
          <!-- 兑换时间 -->
          <td nzAlign="center">{{ data.exchangeTime || '-' }}</td>
          <!-- 过期时间 -->
          <td nzAlign="center">{{ data.expireTime || '-' }}</td>
          <!-- 操作 -->
          <td nzAlign="center" nzRight>
            <button
              nz-button
              nzType="link"
              nzSize="small"
              [disabled]="data.status !== 0"
              (click)="singleVoid(data)"
            >作废</button>
          </td>
        </tr>
      </tbody>
    </nz-table>

    <!-- 分页template -->
    <ng-template #totalTemplate let-total>共有 {{ total }} 条</ng-template>
  </div>
</nz-card>

<!-- S 批量作废 -->
<nz-modal
  nzClassName="custom-model-wrap"
  [nzFooter]="null"
  [(nzVisible)]="isVoidVisible"
  [nzTitle]="'批量作废'"
  (nzOnCancel)="isVoidVisible = false">

  <div *nzModalContent>
    <div class="custom-model-body">
      <nz-form-item>
        <nz-form-label [nzSpan]="4">批次号</nz-form-label>
        <nz-form-control nzFlex="auto">
          <input
            nz-input
            placeholder="请输入批次号"
            [(ngModel)]="toVoidForms.lotNo"
          />
        </nz-form-control>
      </nz-form-item>
    </div>

    <div class="custom-model-foot">
      <div class="custom-foot-cont">
        <button nz-button nzType="default" (click)="isVoidVisible = false">取消</button>
        <button nz-button nzType="primary" [nzLoading]="toVoidForms.loading" (click)="submitBatchVoid()">确定</button>
      </div>
    </div>
  </div>
</nz-modal>
<!-- E 批量作废 -->